const fs = require("fs")
const path = require("path")
const { workPath } = require("../config")

// 确保目录存在
const writeFile = (url, title, txt) => {
  if (!fs.existsSync(url)) {
    fs.mkdirSync(url)
  }
  const childrenWorkPath = path.join(workPath, url)
  const fileName = path.join(childrenWorkPath, `${title}.txt`)
//   console.log(url, childrenWorkPath, txt)
  // 将内容写入文件
  fs.writeFileSync(fileName, txt)
  console.log(`已创建文件：${fileName}`)
}
module.exports = writeFile
